﻿//滚动插件
(function($){
$.fn.extend({
		Scroll:function(opt,callback){
				//参数初始化
				if(!opt) var opt={};
				var _this=this.eq(0).find("ul:first");
				_this.find("li").each(function(index){
					//alert(index+":"+$(this).html());
				});
				var lineH=_this.find("li:first").height(), //获取行高
						line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数，默认为一屏，即父容器高度
						speed=7000, //卷动速度，数值越大，速度越慢（毫秒）
						timer=10000; //滚动的时间间隔（毫秒）
				if(line==0) line=1;
				var upHeight=0-line*lineH;
				//滚动函数
				scrollUp=function(){
						_this.animate({
								marginTop:upHeight
						},speed,function(){
								for(i=1;i<=line;i++){
										_this.find("li").each(function(index){
											//alert(index+":"+$(this).text());
											if(index<4){
												$(this).appendTo(_this);
											}
											
										});
								}
								_this.css({marginTop:0});
						});
				}
				//鼠标事件绑定
				_this.hover(function(){
						clearInterval(timerID);
				},function(){
						timerID=setInterval("scrollUp()",timer);
				}).mouseout();
		}        
})
})(jQuery);

$(document).ready(function(){
base_url = document.URL.slice(0,document.URL.indexOf("index.jsp"));
//疯狂抢购
	 		$.ajax({
				type:"get",
				url: base_url+"web/getProJson.action",
				asyc:true,
				data:"count=4",
				dataType:"JSON",
				success:function(returnedData){
	 				var result = ''; 
					for(var i=0;i<returnedData.length;++i)
					{	
						var title = returnedData[i].caption;
						var linkUrl = base_url+'product.jsp?id='+returnedData[i].id;
						var picUrl = returnedData[i].picUrl;
					 	var	price = returnedData[i].goldPrice;
						var remark = returnedData[i].remark;
						result +='<li><dl><dt><a target="_blank" href='+linkUrl+'><img src='+picUrl+' alt='+title+'></a></dt>' +
						'<dd class="p_Price">爱心币：<em>￥<span>'+price+'</span></em></dd>' +
						'<dd class="p_Name"><a target="_blank" href='+linkUrl+'>'+title+'<br><font color="orange">'+remark+'</font></a></dd>' +
						'</dl></li>';
					}
					
				$('#crazebuy').html(result);
				$('#crazebuy').show();
				},
			error:function()
			 {
				alert('ajax执行错误！');
			 }
			});
	//新上架商品（暂未配置）
	 		
	 	$.ajax({
				type:"get",
				url: base_url+"web/getProJson.action",
				asyc:true,
				data:"count=12",
				dataType:"JSON",
				success:function(returnedData){
	 				var result = '';             		 
					for(var i=0;i<returnedData.length;++i)
					{	
						var title = returnedData[i].caption;
						var linkUrl = base_url+'product.jsp?id='+returnedData[i].id;
						var picUrl = returnedData[i].picUrl;
					 	var	price = returnedData[i].goldPrice;
						var remark = returnedData[i].remark;
						result +='<li><dl><dt><a target="_blank" href="'+linkUrl+'"><img src="'+picUrl+'" alt="'+title+'"></a></dt> <dd class="p_Name"><a target="_blank" href="'+linkUrl+'">'+title+'<br><font color="orange">'+remark+'</font></a></dd><dd class="p_Price">爱心币：<em>￥'+price+'</em></dd></dl></li>';
					}
				$('#newproducts').empty();
				$('#newproducts').append(result);
				$("#scrollDiv").Scroll({line:1,speed:500,timer:4000});//滚动
				},
			error:function()
			 {
				alert('ajax执行错误！');
			 }
			});
	 
	 		//爱心通知
	 	 	 	$.ajax({
				type:"get",
				url: base_url+"web/getInforJson.action",
				asyc:true,
				data:{type:1,count:6},
				dataType:"JSON",
				success:function(returnedData){
	 				var result = '';
	 				if(returnedData.length==0)
	 					return ;
					for(var i=0;i<returnedData.length;++i)
					{	
						var linkUrl = base_url+'web/viewInfor.action?id='+returnedData[i].id;
						var time = returnedData[i].time;
						var title = returnedData[i].title;
						result +=' <li><span style="color:orange;font-size:14px;">></span><a target="_blank" href='+linkUrl+'>'+title+'【'+time+'】</a></li>';
					}
				$('#loveTozhi').empty();
				$('#loveTozhi').append(result);
				},
			error:function()
			 {
				alert('ajax执行错误！');
			 }
			});
	 	 	//爱心新闻动态
	 	 	 	$.ajax({
				type:"get",
				url: base_url+"web/getInforJson.action",
				asyc:true,
				data:{type:0,count:6},
				dataType:"JSON",
				success:function(returnedData){
	 				var result = ''; 
	 				if(returnedData.length==0)
	 					return ;
					for(var i=0;i<returnedData.length;++i)
					{	
						var linkUrl = base_url+'web/viewInfor.action?id='+returnedData[i].id;
						var time = returnedData[i].time; 
						var title = returnedData[i].title;
						result +=' <li><a target="_blank" href='+linkUrl+'><span style="color:orange;font-size:14px;">></span>'+title+'【'+time+'】</a></li>';
					}
					result += '<li id="more_news"><a target="_blank" href="http://cycs.swust.edu.cn:8080/ShopOnline/lists.jsp">>>More>></a></li>';
				$('#thelastnews').empty();
				$('#thelastnews').append(result);
				},
			error:function()
			 {
				alert('ajax执行错误');
			 }
			});
	 	 	//爱心心得文章
	 	 	 	$.ajax({
				type:"get",
				url: base_url+"web/getInforJson.action",
				asyc:true,
				data:{type:3,count:6},
				dataType:"JSON",
				success:function(returnedData){
	 				var result = '';      
	 					if(returnedData.length==0)
	 					return ;
					for(var i=0;i<returnedData.length;++i)
					{	
						var linkUrl = base_url+'web/viewInfor.action?id='+returnedData[i].id;
						var time = returnedData[i].time; 
						var title = returnedData[i].title;
						result +='<li><span style="color:orange;font-size:14px;">></span><a target="_blank" href='+linkUrl+'>'+title+'【'+time+'】</a></li>';
					}
				$('#new_order').empty();
				$('#new_order').append(result);
				},
			error:function()
			 {
				alert('ajax执行错误');
			 }
			});
	 	 	//爱心鸣谢
	 	 	 	$.ajax({
				type:"get",
				url: base_url+"web/getInforJson.action",
				asyc:true,
				data:{type:2,count:6},
				dataType:"JSON",
				success:function(returnedData){
	 				var result = '';  
	 					if(returnedData.length==0)
	 					return ;
					for(var i=0;i<returnedData.length;++i)
					{	
						var linkUrl = base_url+'web/viewInfor.action?id='+returnedData[i].id;
						var time = returnedData[i].time; 
						var title = returnedData[i].title;
						result +=' <li><span style="color:orange;font-size:14px;">></span><a target="_blank" href='+linkUrl+'>'+title+'【'+time+'】</a></li>';
					}
				$('#top_provider').empty();
				$('#top_provider').append(result);
				},
			error:function()
			 {
				alert('ajax执行错误');
			 }
			});
});
